var util = require('../../../../utils/util.js')
var _this
Page({
  data: {
    filePath: ''
  },
  nextButtonSelected: (e) => {

    wx.navigateTo({
      url: '../matchResult/matchResult',
    })
  },
  chooseImage: () => {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths)
        _this.setData({
          filePath: tempFilePaths
        })
      },
      fail(){
        _this.setData({
          filePath: ''
        })
      }
    })
  },
  onLoad: function()  {
    _this = this;

  },
  fileUpload: (e) => {
    if (_this.data.filePath == ''){
      wx.showToast({
        title: '请选择一张靓照吧',
        icon: 'none'
      })
      return
    }
    util.fileUpload(_this.requestDidResponse, _this.requestDidFaild,_this.data.filePath[0])
  },
  requestDidResponse: (res) => {
    var data = JSON.parse(res)
    if (data.status == '200') {
      wx.navigateTo({
        url: '../matchResult/matchResult',
      })
    }else{
      wx.showToast({
        title: '上传失败',
        icon: 'none'
      })
    }
  },
  requestDidFaild: (res) => {
    console.log(res)
    wx.showToast({
      title: '网络异常',
      icon: 'none'
    })
  }
})